package leetcode.L1000;

import java.util.HashMap;
import java.util.Map;

public class EX781 {
    public int numRabbits(int[] answers) {
        Map<Integer, Integer> map = new HashMap<>();
        for(int i = 0;i<answers.length;i++){
            map.put(answers[i], map.getOrDefault(answers[i],0)+1);
        }
        int res = 0;
        for(Integer key: map.keySet()){
            Integer value = map.get(key);
            res+=value/(key+1) *(key+1);
            if(value%(key+1)!=0){
                res+=(key+1);
            }
        }

        return res;
    }
}
